<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initLoder()
	{
		 $admin_loader = new Zend_Loader_Autoloader_Resource(array(
			'basePath'  => APPLICATION_PATH.'/modules/admin',
			'namespace' => 'Admin',
		));
		$admin_loader->addResourceType('model', 'models', 'Model')
			->addResourceType('form', 'forms', 'Form');
	} 
	/*protected function _initSmarty()
	{
		require_once 'Smarty.php';
		// Module init
		$front = Zend_Controller_Front::getInstance();
		$front->addModuleDirectory(APPLICATION_PATH.'/modules');
		
		// Smarty init
		$this->view = new Zend_View_Smarty(); 
		$this->view->setScriptPath(APPLICATION_PATH.'/modules'); 

		$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($this->view); 
		$viewRenderer->setViewBasePathSpec(APPLICATION_PATH); 
		
		$viewRenderer->setViewScriptPathSpec(':module/views/scripts/:controller/:action.:suffix'); 
		$viewRenderer->setViewScriptPathNoControllerSpec(':action.:suffi x'); 
		$viewRenderer->setViewSuffix('tpl'); 
		
		Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
	}*/
	protected function _initView()
	{
		// initialize smarty view
		$view = new Ext_View_Smarty($this->getOption('smarty'));
		// setup viewRenderer with suffix and view
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
		$viewRenderer->setViewSuffix('tpl');
		$viewRenderer->setView($view);
		
		// ensure we have layout bootstraped
		$this->bootstrap('layout');
		// set the tpl suffix to layout also
		$layout = Zend_Layout::getMvcInstance();
		$layout->setViewSuffix('tpl');
		
		return $view;
	}
	protected function _initLogin()
	{
		$cor_us = Zend_Auth::getInstance()->getIdentity();
		if(empty($cor_us)){
			$form = new Application_Model_Form_Login();
			$this->view->form=$form;
		} else {
			$this->view->form='<div class="login_form"> Hello dear '.$cor_us->first_name.'</div>';
			$this->view->correntUser = $cor_us;
		}
	}
	protected function _initAcl()
	{
		$acl = new Zend_Acl();
		// Добавление групп в реестр ролей с использованием Zend_Acl_Role
		// Гость не наследует управление доступом
		$roleGuest = new Zend_Acl_Role('guest');
		$acl->addRole($roleGuest);
		
		// Сотрудник наследует от гостя
		$acl->addRole(new Zend_Acl_Role('TEACHER'), $roleGuest);
		
		// Администатор не наследует управление доступом
		$acl->addRole(new Zend_Acl_Role('ADMIN'));
		
		$acl->add(new Zend_Acl_Resource('admin_section'));
		$acl->add(new Zend_Acl_Resource('teacher_section'));
		$acl->add(new Zend_Acl_Resource('default_section'));
	}
}
